package com.byref.liteflowdemo.cmp.decleardemo;

import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowFact;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.enums.NodeTypeEnum;
import lombok.extern.slf4j.Slf4j;

/**
 * @author BYREF
 */
@LiteflowComponent("declare")
@Slf4j
public class DeclareConfig {

    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BOOLEAN,
            nodeType = NodeTypeEnum.BOOLEAN
            , nodeId = "isVip")
    public boolean isVip(NodeComponent nodeComponent, @LiteflowFact("user") UserInfo userInfo) {
        log.info("RUN is access, is Vip: {}", userInfo);
        return userInfo.isVip();
    }

    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,
            nodeType = NodeTypeEnum.COMMON
            , nodeId = "genCoupon")
    public void genCoupon(NodeComponent nodeComponent, @LiteflowFact("user") UserInfo userInfo) {
        log.info("RUN genCoupon, is Vip: {}", userInfo);
        if (userInfo.isVip()) {
            MyContext contextBean = nodeComponent.getContextBean(MyContext.class);
            contextBean.setCoupon("vip_coupon");
        }
    }

    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS,
            nodeType = NodeTypeEnum.COMMON
            , nodeId = "sendCoupon")
    public void sendCoupon(NodeComponent nodeComponent, @LiteflowFact("coupon") String coupon) {
        log.info("RUN sendCoupon, is Vip: {}", coupon);
    }
}
